var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
var imgUrl = globalData.imgUrl;
Page({

  data: {
    imgUrl: imgUrl,
    user: [],
    money:"",
  },
  load: function () {
    let that = this;
    let user = wx.getStorageSync(globalData.userInfoKey);
    this.setData({
      user: user
    })
    commonUtil.showLoading("请稍等...");
    wx.request({
      header: { "Cookie": getApp().getJSESSIONID(), "content-Type": "application/x-www-form-urlencoded" },
      url: httpsUrl + "/bonus/notofaccount",
      dataType: "json",
      method: "GET",
      success: function (res) {
        commonUtil.hideLoading();
        console.log("返回：" + JSON.stringify(res));
        res = res.data;
        if (res.code == 0) {
          user.notofaccount = res.data;
          that.setData({
            user: user
          })
        }
      }
    })
  },

  putForward:function(){
    let user = this.data.user;
    var params = new Object();
    let money = this.data.money;
    params.money = money;
    //let balanceTotal = Number(user.balance) + Number(user.bonus);
    if (commonUtil.isEmpty(money)){
      commonUtil.showModal("金额不能为空");
      return;
    }else{
      if (Number(money) > Number(user.bonus)){
        commonUtil.showModal("余额不足");
        return;
      }
      params.serviceMoney = Number(money) * 0.006;//按付款金额收取手续费，按金额0.1%收取，最低1元，最高25元
      params.realMoney = Number(money) - Number(params.serviceMoney);
    }
    console.log(JSON.stringify(params));
    commonUtil.showLoading("请稍等...");
    wx.request({
      header: { "Cookie": getApp().getJSESSIONID(), "content-Type": "application/x-www-form-urlencoded" },
      url: httpsUrl + "/userManage/addExtractCashApply",
      dataType: "json",
      method: "POST",
      data: params,
      success: function (res) {
        commonUtil.hideLoading();
        console.log("提现返回：" + JSON.stringify(res));
        res = res.data;
        if (res.code == 0) {
          wx.navigateBack({
            delta: 1
          })
        } else {
          commonUtil.showModal(res.msg);
        }
      }
    })
  },
  money:function(e){
    let val = e.detail.value;
    this.setData({ money: val })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.load();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})